/*
* acooly.cn Inc.
* Copyright (c) 2017 All Rights Reserved.
* create by ouwen
* date:2017-09-20
*/
package com.yiji.fintech.musfinance.web;

import com.acooly.core.common.web.AbstractJQueryEntityController;
import com.yiji.fintech.musfinance.base.enums.CardTypeEnum;
import com.yiji.fintech.musfinance.base.enums.PersonalCorporateTypeEnum;
import com.yiji.fintech.musfinance.common.utils.cache.CacheConstant;
import com.yiji.fintech.musfinance.common.utils.cache.CacheService;
import com.yiji.fintech.musfinance.entity.BankCardBin;
import com.yiji.fintech.musfinance.service.BankCardBinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * center_bank_card_bin 管理控制器
 * 
 * @author ouwen
 * Date: 2017-09-20 13:41:34
 */
@Controller
@RequestMapping(value = "/manage/carbin/bankCardBin")
public class BankCardBinManagerController extends AbstractJQueryEntityController<BankCardBin, BankCardBinService> {
	

	{
		allowMapping = "*";
	}

	@SuppressWarnings("unused")
	@Autowired
	private BankCardBinService bankCardBinService;
	@Autowired
	private CacheService cacheService;

	@Override
	protected BankCardBin doSave(HttpServletRequest request, HttpServletResponse response, Model model, boolean isCreate) throws Exception {
		BankCardBin bankCardBinDo = loadEntity(request);
		//示范卡号跟据卡长度、卡标识、卡标识长度自动生成
		StringBuilder sb = new StringBuilder(bankCardBinDo.getCardFlag());
		for(int i=0;i < (bankCardBinDo.getCardLength()-bankCardBinDo.getCardFlagLen());i++){
			sb.append("x");
		}
		bankCardBinDo.setCardNum(sb.toString());
		BankCardBin bankCardBin = super.doSave(request, response, model, isCreate);
		cacheService.doUpdateMutiCache(CacheConstant.CENTER_BANKCARDBIN_MUTICACHE,BankCardBinService.class);//更新carbin多级缓存
		return bankCardBin;
	}
	@Override
	protected void referenceData(HttpServletRequest request, Map<String, Object> model) {
		model.put("allPersonalCorporateTypes", PersonalCorporateTypeEnum.mapping());
		model.put("allCardTypes", CardTypeEnum.mapping());
	}

}
